<?php

function czy_setup() {

	// This theme uses wp_nav_menu() in one location.
	register_nav_menu( 'primary', '主菜单' );

	/*
	 * This theme uses a custom image size for featured images, displayed on
	 * "standard" posts and pages.
	 */
	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 772, 329, true );

	add_image_size( 'post-thumbnail-370-250', 370, 250, true );
	add_image_size( 'post-thumbnail-70-70', 70, 70, true );
	add_image_size( 'post-thumbnail-315-219', 315, 249, true );
	add_image_size( 'post-thumbnail-291-264', 291, 264, true );

}
add_action( 'after_setup_theme', 'czy_setup' );

function get_new_category() {
	$categories = get_terms('cat-news', 'hide_empty=0' );//print_r($categories);

	return $categories;
}

function get_product_category() {
	$categories = get_terms('cat-product', 'hide_empty=0' );//print_r($categories);

	return $categories;
}

function get_the_new_tag( $id = false ) {
	$categories = get_the_terms( $id, 'tag-news' );
	if ( ! $categories || is_wp_error( $categories ) )
		$categories = array();

	$categories = array_values( $categories );

	foreach ( array_keys( $categories ) as $key ) {
		_make_cat_compat( $categories[$key] );
	}

	/**
	 * Filter the array of categories to return for a post.
	 *
	 * @since 3.1.0
	 *
	 * @param array $categories An array of categories to return for the post.
	 */
	return apply_filters( 'get_the_new_tag', $categories );
}

function the_new_tag( $post_id = false)
{
	global $post;

	if( !$post_id )
		$post_id = $post->ID;

	$tags = get_the_new_tag($post_id);
	
	$str = '';
	foreach($tags as $tag) {
		$str .= "{$tag->name},";
	}

	echo substr($str, 0, -1);
}
//文章浏览次数
function get_post_views ($post_id) {
    $count_key = 'post_views_count';
    $count = get_post_meta($post_id, $count_key, true);
    if ($count == '') {
        delete_post_meta($post_id, $count_key);
        add_post_meta($post_id, $count_key, '0');
        $count = '0';
    }
    echo number_format_i18n($count);
}

//页码/分页/翻页效果
function wpdx_paging_nav(){
	global $wp_query;
 
	$big = 999999999; // 需要一个不太可能的整数
 
	$pagination_links = paginate_links( array(
		'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
		'format' => '?paged=%#%',
		'current' => max( 1, get_query_var('paged') ),
		'total' => $wp_query->max_num_pages
	) );
 
echo $pagination_links;
}


